/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package guiutilities;

import image.edge.EdgeDetector.DIRECCTION;
import image.processing.ImageProcessor.CompressAlgorithm;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import org.jdesktop.application.ResourceMap;

/**
 *
 * @author tommy
 */
public class jDirectionDialog extends JDialog {
	private boolean confirmed;
	private JLabel jHeader;
	private ButtonGroup optionsGroup;
	private JRadioButton jHorizontal, jVertical, jDiagonalR, jDiagonalL;
	private JButton jConfirmOperation;
	
	
	public jDirectionDialog(JFrame parent, ResourceMap resourceMap) {
		// Dialog for browsing and storing 2 images to perform operations among
		// them
		super(parent,"Select direction", true);
		
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
		setPreferredSize(new Dimension(512,196));
		setMaximumSize(new Dimension(512,196));
		setResizable(false);
		setSize(512, 196);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		jHeader = new JLabel("Choose Direction: ");
		
		optionsGroup = new ButtonGroup();
		jHorizontal = new JRadioButton("Horizontal");
		jVertical = new JRadioButton("Vertical", true);
		jDiagonalR = new JRadioButton("Right Diagonal");
		jDiagonalL = new JRadioButton("Left Diagonal");

		optionsGroup.add(jHorizontal);
		optionsGroup.add(jVertical);
		optionsGroup.add(jDiagonalR);
		optionsGroup.add(jDiagonalL);
		
		jConfirmOperation = new JButton();
        jConfirmOperation.setText(resourceMap.getString("jConfirmOperation.text")); // NOI18N
        jConfirmOperation.setName("jConfirmOperation"); // NOI18N
		jConfirmOperation.setPreferredSize(new Dimension(50,50));
		jConfirmOperation.setMinimumSize(new Dimension(50,50));
        jConfirmOperation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jConfirmOperationActionPerformed(evt);
            }
        });
		
		// Add components to Dialog
		getContentPane().add(jHeader);
		getContentPane().add(jHorizontal);
		getContentPane().add(jVertical);
		getContentPane().add(jDiagonalR);
		getContentPane().add(jDiagonalL);
		getContentPane().add(jConfirmOperation);
	}
	
	public boolean isConfirmed() {
		return this.confirmed;
	}
	
	public DIRECCTION getDirection() {
		DIRECCTION dir = DIRECCTION.VERTICAL;
		
		if (isConfirmed()) {
			if (jHorizontal.isSelected()) {
				dir = DIRECCTION.HORIZONTAL;
			} else if (jVertical.isSelected()) {
				dir = DIRECCTION.VERTICAL;
			} else if (jDiagonalR.isSelected()){
				dir = DIRECCTION.DIAGONALRIGHT;
			} else {
				dir = DIRECCTION.DIAGONALLEFT;
			}
		}
		
		return dir;
	}
		
	private void jConfirmOperationActionPerformed(java.awt.event.ActionEvent evt) {                                                     
		this.confirmed = true;
		this.dispose();
	}
}
